package Year21_Month12.day1205;

public class Solution2 {
    class Solution {
        public int maxProfit(int[] prices) {
            int i = 0;//记录最小价格下标
            int max = 0;//记录差价
            int j = 0;//用来进行遍历
            while(j < prices.length){
                if(prices[j] < prices[i]){
                    i = j;
                }else if(prices[j] - prices[i] > max){
                    max = prices[j] - prices[i];
                }
                j++;
            }
            return max;
        }
    }

}
